package org.thanos.demo;

import io.rsocket.transport.netty.client.TcpClientTransport;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.util.MimeTypeUtils;

@SpringBootApplication
public class RSocketClientBootstrap {

    @Value("${rsocket.server.url}")
    private String url;

    @Value("${rsocket.server.port}")
    private Integer port;

    public static void main(String[] args) {
        new SpringApplicationBuilder(RSocketClientBootstrap.class)
                .web(WebApplicationType.REACTIVE)
                .run(args);
    }

    @Bean
    public RSocketRequester rSocketRequester(RSocketStrategies strategies) {
        return RSocketRequester.builder()
                .dataMimeType(MimeTypeUtils.ALL)
                .rsocketStrategies(strategies)
                .transport(TcpClientTransport.create(url, port));
    }
}
